<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/3/18
 * Time: 10:00
 */

namespace app\controller\admin;
use app\model\admin\Order AS model;
use app\model\admin\OrderInfo AS info;
class Order extends Base
{
    public function list(){

        $order = model::where(['status' => 2])
            ->with(['info'])
            ->paginate([
                'page' => $this->page,
                'list_rows' => $this->size
            ]);
        return $this->view('/admin/order/list',['list' => $order]);
    }

    public function info($id = 0,$keyword = ''){
        $info = model::find($id);
        if (!empty($keyword)){
            $list = info::where('keyword',$keyword)->select();
        }else{
            $list = info::where('order_no',$info->order_no)->select();
        }
        return $this->view('/admin/order/info',['info' => $info,'list' => $list]);
    }

    public function save(){
        $id = input('id');
        $data = input('data');
        $keyword = input('keywords');
        $info = model::find($id);
        if (empty($info->id))
            return $this->fail('数据不存在');
        if (!empty($keyword)){
            foreach (info::where('order_no',$info->order_no)->select() AS $key => $value)$value->delete();
            foreach ($keyword AS $key => $value)
                $savell[] = array_merge($value,[
                    'order_no' => $info->order_no,
                    'status' => $info->status,
                    'price_type' => $info->price_type
                ]);
            if(!empty($savell))(new info())->saveAll($savell);
        }
        $info->save($data);
        return $this->msg();
    }
}